import json
data = """
[
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 100,
            "parentId": 0,
            "ancestors": "0",
            "deptName": "若依科技",
            "orderNum": 0,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 101,
            "parentId": 100,
            "ancestors": "0,100",
            "deptName": "深圳总公司",
            "orderNum": 1,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 102,
            "parentId": 100,
            "ancestors": "0,100",
            "deptName": "长沙分公司",
            "orderNum": 2,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 103,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "研发部门",
            "orderNum": 1,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 104,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "市场部门",
            "orderNum": 2,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 105,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "测试部门",
            "orderNum": 3,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 106,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "财务部门",
            "orderNum": 4,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 107,
            "parentId": 101,
            "ancestors": "0,100,101",
            "deptName": "运维部门",
            "orderNum": 5,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 108,
            "parentId": 102,
            "ancestors": "0,100,102",
            "deptName": "市场部门",
            "orderNum": 1,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        },
        {
            "createBy": "admin",
            "createTime": "2025-05-07 09:04:10",
            "updateBy": null,
            "updateTime": null,
            "remark": null,
            "deptId": 109,
            "parentId": 102,
            "ancestors": "0,100,102",
            "deptName": "财务部门",
            "orderNum": 2,
            "leader": "若依",
            "phone": "15888888888",
            "email": "ry@qq.com",
            "status": "0",
            "delFlag": "0",
            "parentName": null,
            "children": []
        }
    ]
"""

def list_to_tree(data, parent_id=None):
    """
    将列表转换为树形结构

    参数：
    data: 列表数据
    parent_id: 父节点ID，默认为None

    返回值：
    树形结构数据
    """
    data_dict = {item['deptId']: item for item in data}
    tree = []
    for item in data:
        if item['parentId'] == parent_id:
           children = list_to_tree()